package com.cmict.data.form.api.util;


import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cmict.data.form.api.entity.dataobject.SysFormDO;
import com.cmict.data.form.api.entity.vo.SysFromDataColumnVo;
import com.cmict.data.form.api.service.SysCurrencyService;
import com.cmict.data.form.api.service.SysFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.*;

/**
 * @description: 判断是否为空工具类
 * @author: qiaoyu
 * @create: 2022-07-08 22:57
 **/
@Component
public class IsNullUtil {
    @Autowired
    private SysCurrencyService sysCurrencyService;
    private static SysCurrencyService realsysCurrencyService;

    @Autowired
    private  SysFormService sysFormService;
    private static SysFormService realsysFormService;

    @PostConstruct
    public void init() {
        realsysCurrencyService = sysCurrencyService;
        realsysFormService = sysFormService;
    }

    //数据库测
	public static Boolean isnull(SysFromDataColumnVo column) {
	    if(ObjectUtil.isNotEmpty(column.getIsnullable())){
            if(column.getIsnullable().equals("NO") && ObjectUtil.isEmpty(column.getValue())){
                return false;
            }
        }
		return true;
	}
    //表单解析侧-是否必填
    public static Boolean isnullForm(String columnName, String value,SysFormDO sysFormDO) {
        Boolean req = true;
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                if(ObjectUtil.isNotEmpty(field)){
                    if(field.equals(columnName)){
                        if(config.getString("required").equals("true") && ObjectUtil.isEmpty(value)){
                            return false;
                        }
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    if(ObjectUtil.isNotEmpty(field)){
                        if(field.equals(columnName)){
                            if(configgg.getString("required").equals("true") && ObjectUtil.isEmpty(value)){
                                return false;
                            }
                        }
                    }
                }
            }
        }
        return req;
    }
    //表单解析侧-默认值
    public static String defaultForm(String columnName, SysFormDO sysFormDO) {
        String req = null;
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                if(ObjectUtil.isNotEmpty(field)){
                    if(field.equals(columnName) && ObjectUtil.isNotEmpty(config.getString("defaultValue"))){
                        req = config.getString("defaultValue");
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    if(ObjectUtil.isNotEmpty(field)){
                        if(field.equals(columnName) && ObjectUtil.isNotEmpty(configgg.getString("defaultValue"))){
                            req = configgg.getString("defaultValue");
                        }
                    }
                }
            }
        }
        return req;
    }

    //表单模板-是否必填
    public static Boolean isnullFormtemp(String columnName, String value,SysFormDO sysFormDO) {
        Boolean req = false;
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                if(ObjectUtil.isNotEmpty(field)){
                    if(field.equals(columnName)){
                        req = Boolean.valueOf(config.getString("required"));
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    if(ObjectUtil.isNotEmpty(field)){
                        if(field.equals(columnName)){
                            if(configgg.getString("required").equals("true") && ObjectUtil.isEmpty(value)){
                                req = Boolean.valueOf(configgg.getString("required"));
                            }else{
                                req = false;
                            }
                        }
                    }
                }
            }
        }
        return req;
    }
    //表单解析导出模板侧-下拉值
    public static String selectForm(String columnName, SysFormDO sysFormDO) {
        String req = "";
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "select".equals(tagIcon) || "radio".equals(tagIcon) || "checkbox".equals(tagIcon)){
                    if(field.equals(columnName)){
                        String datatype = fields.getJSONObject(i).getString("dataType");
                        req = AssemblyTypeUtil.modelDataMapping(fields.getJSONObject(i),datatype);
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "select".equals(tagIcon) || "radio".equals(tagIcon) || "checkbox".equals(tagIcon)){
                        if(field.equals(columnName)){
                            String datatype = children.getString("dataType");
                            req = AssemblyTypeUtil.modelDataMapping(children,datatype);
                        }
                    }
                }
            }
        }
        if(ObjectUtil.isNotEmpty(req)){
            return "值："+req ;
        }
        return null ;
    }

    //表单解析数据导入侧-下拉值
    public static Map<Object,Object> selectInForm(String columnName, String value, SysFormDO sysFormDO) {
        Map<Object,Object> map = new HashMap<>();
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "select".equals(tagIcon) || "radio".equals(tagIcon) || "checkbox".equals(tagIcon)){
                    if(field.equals(columnName)){
                        String datatype = fields.getJSONObject(i).getString("dataType");
                        map = IsSelectUtil.selectDataMapping(fields.getJSONObject(i),value,datatype);
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "select".equals(tagIcon) || "radio".equals(tagIcon) || "checkbox".equals(tagIcon)){
                        if(field.equals(columnName)){
                            String datatype = children.getString("dataType");
                            map = IsSelectUtil.selectDataMapping(children,value,datatype);
                        }
                    }
                }
            }
        }
        return map;
    }

    //表单解析导出模板侧-下拉多选单选获取
    public static String selectFormSingleOrMultiple(String columnName, SysFormDO sysFormDO) {
        String message = "";
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "select".equals(tagIcon) || "radio".equals(tagIcon) || "checkbox".equals(tagIcon)){
                    if(field.equals(columnName)) {
                        Boolean req = Boolean.valueOf(fields.getJSONObject(i).getString("multiple"));
                        if (req || "checkbox".equals(tagIcon)) {
                            message = "可多选：选项一,选项二 不同选项间需用英文(半角)隔开";
                        } else {
                            message = "单选：选项一";
                        }
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "select".equals(tagIcon) || "radio".equals(tagIcon) || "checkbox".equals(tagIcon)){
                        if(field.equals(columnName)) {
                            Boolean req = Boolean.valueOf(children.getString("multiple"));
                            if (req || "checkbox".equals(tagIcon)) {
                                message = "可多选：选项一,选项二 不同选项间需用英文(半角)隔开";
                            } else {
                                message = "单选：选项一";
                            }
                        }
                    }
                }
            }
        }
        return message;
    }

    //表单解析导出模板侧-日期模板
    public static String dateTypeForm(String columnName, SysFormDO sysFormDO) {
        String req = "";
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "date".equals(tagIcon) || "time".equals(tagIcon) || "datetime".equals(tagIcon)){
                    if(field.equals(columnName)){
                        String datatype = fields.getJSONObject(i).getString("format");
                        req = datatype;
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "date".equals(tagIcon) || "time".equals(tagIcon) || "datetime".equals(tagIcon)){
                        if(field.equals(columnName)){
                            String datatype = children.getString("format");
                            req = datatype;
                        }
                    }
                }
            }
        }
        if(req.equals("yyyy-MM-dd")){
                req = "年-月-日（请设置为文本格式导入）";
        }else if(req.equals("yyyy-MM-dd HH:mm:ss")){
            req = "年-月-日 时:分:秒（请设置为文本格式导入）";
        }else if(req.equals("yyyy-MM")){
            req = "年-月（请设置为文本格式导入）";
        }else if(req.equals("yyyy")){
            req = "年（请设置为文本格式导入）";
        }else if(req.equals("HH:mm:ss")){
            req = "时:分:秒（请设置为文本格式导入）";
        }
        return req;
    }
    //表单解析导出模板侧-日期实例
    public static String dateTypeFormExample(String columnName, SysFormDO sysFormDO) {
        String req = dateTypeForm(columnName,sysFormDO);
        if(req.equals("年-月-日（请设置为文本格式导入）")){
            req = "2022-10-10";
        }else if(req.equals("年-月-日 时:分:秒（请设置为文本格式导入）")){
            req = "2022-10-10 18:08:05";
        }else if(req.equals("年-月（请设置为文本格式导入）")){
            req = "2022-10";
        }else if(req.equals("年（请设置为文本格式导入）")){
            req = "2022";
        }else if(req.equals("时:分:秒（请设置为文本格式导入）")){
            req = "18:08:05";
        }
        return req;
    }
    //表单解析数据导入侧-日期
    public static Map<Object,Object> DateInForm(String columnName, String value, SysFormDO sysFormDO) {
        Map<Object,Object> map = new HashMap<>();
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "date".equals(tagIcon) || "time".equals(tagIcon) || "datetime".equals(tagIcon)){
                    if(field.equals(columnName)){
                        String datatype = fields.getJSONObject(i).getString("format");
                        map = IsDateUtil.dateMapping(value,datatype);
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "date".equals(tagIcon) || "time".equals(tagIcon) || "datetime".equals(tagIcon)){
                        if(field.equals(columnName)){
                            String datatype = children.getString("format");
                            map = IsDateUtil.dateMapping(value,datatype);
                        }
                    }
                }
            }
        }
        return map;
    }

    //表单模板-是否数据重复校验
    public static Boolean dataRepeat(String columnName, String value,SysFormDO sysFormDO) {
        Boolean req = false;
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                if(ObjectUtil.isNotEmpty(field)){
                    if(field.equals(columnName)){
                        req = Boolean.valueOf(config.getString("repeatVerify"));
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    if(ObjectUtil.isNotEmpty(field)){
                        if(field.equals(columnName)){
                            if(ObjectUtil.isNotEmpty(configgg.getString("repeatVerify"))){
                                if(configgg.getString("repeatVerify").equals("true") && ObjectUtil.isEmpty(value)){
                                    req = Boolean.valueOf(configgg.getString("repeatVerify"));
                                }else{
                                    req = false;
                                }
                            }
                        }
                    }
                }
            }
        }
        return req;
    }

    //表单解析侧-是否重复值校验
    public static Boolean isDataRepeat(String columnName, String value,SysFormDO sysFormDO) {
        Boolean req = true;
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                if(ObjectUtil.isNotEmpty(field)){
                    if(field.equals(columnName)){
                        if(ObjectUtil.isNotEmpty(config.getString("repeatVerify"))){
                            if(config.getString("repeatVerify").equals("true")){
                                if(ObjectUtil.isNotEmpty(columnName) && ObjectUtil.isNotEmpty(sysFormDO.getTableName())){
                                    String sql = "SELECT * FROM "+ sysFormDO.getTableName();
                                    List<Map<String, Object>> mapvalue =  realsysCurrencyService.isDataRepeat(sql);
                                    if(ObjectUtil.isNotEmpty(mapvalue)){
                                        List<Map<String, Object>> mapvector = AssemblyTypeUtil.associatedDataMapping(sysFormDO.getTableName(), mapvalue, "static").getData();
                                        //List<Map<String, Object>> mapvector = (List<Map<String, Object>>) data;
                                        for (Map<String,Object> map: mapvector) {
                                            if(map.get(columnName).equals(value)){
                                                return false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    if(ObjectUtil.isNotEmpty(field)){
                        if(field.equals(columnName)){
                            if(ObjectUtil.isNotEmpty(configgg.getString("repeatVerify"))){
                                if(configgg.getString("repeatVerify").equals("true")){
                                    if(ObjectUtil.isNotEmpty(columnName) && ObjectUtil.isNotEmpty(sysFormDO.getTableName())){
                                        String sql = "SELECT * FROM "+ sysFormDO.getTableName();
                                        List<Map<String, Object>> mapvalue =  realsysCurrencyService.isDataRepeat(sql);
                                        if(ObjectUtil.isNotEmpty(mapvalue)){
                                            List<Map<String, Object>> mapvector = AssemblyTypeUtil.associatedDataMapping(sysFormDO.getTableName(), mapvalue, "static").getData();
                                            //List<Map<String, Object>> mapvector = (List<Map<String, Object>>) data;
                                            for (Map<String,Object> map: mapvector) {
                                                if(map.get(columnName).equals(value)){
                                                    return false;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return req;
    }
    //表单解析数据导入侧-部门
    public static Map<Object,Object> departForm(String columnName, String value, SysFormDO sysFormDO) {
        Map<Object,Object> map = new HashMap<>();
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "depart".equals(tagIcon)){
                    if(field.equals(columnName)){
                        map = IsDepartUtil.departDataMapping(fields.getJSONObject(i),value);
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "depart".equals(tagIcon)){
                        if(field.equals(columnName)){
                            map = IsDepartUtil.departDataMapping(childrenOne,value);
                        }
                    }
                }
            }
        }
        return map;
    }
    //表单解析导出模板侧-部门
    public static String deptForm(String columnName, SysFormDO sysFormDO) {
        String req = "";
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "depart".equals(tagIcon)){
                    if(field.equals(columnName)){
                        req = "部门导入必须是全路径，如：xxx/xxx/xxx。如果路径有误或者名称错误将导致无法显示";
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "depart".equals(tagIcon)){
                        if(field.equals(columnName)){
                            req = "部门导入必须是全路径，如：xxx/xxx/xxx。如果路径有误或者名称错误将导致无法显示";
                        }
                    }
                }
            }
        }
        if(ObjectUtil.isNotEmpty(req)){
            return req ;
        }
        return null ;
    }
    //数据插入detetime类型时，区分什么时间类型（yyyy、yyyy-hh-dd）等做转换工具
    public static Map<Object,Object> DateChange(String columnName, String value, String tableName) {
        //主表form
        SysFormDO sysFormDO= realsysFormService.selectOneByTableName(tableName);
        Map<Object,Object> map = new HashMap<>();
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "date".equals(tagIcon) || "time".equals(tagIcon)){
                    if(field.equals(columnName)){
                        String datatype = fields.getJSONObject(i).getString("format");
                        map = IsDateInUtil.datechange(value,datatype);
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "date".equals(tagIcon)){
                        if(field.equals(columnName)){
                            String datatype = children.getString("format");
                            map = IsDateInUtil.datechange(value,datatype);
                        }
                    }
                }
            }
        }
        return map;
    }

    //数据插入decimal、double类型时，获取%号转换
    public static String percentageChange(String columnName, String value, String tableName) {
        //主表form
        SysFormDO sysFormDO= realsysFormService.selectOneByTableName(tableName);
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String numberType = config.getString("numberType");
                if(ObjectUtil.isNotEmpty(field) && "percentage".equals(numberType)){
                    if(field.equals(columnName)){
                        Double a = (double)Integer.parseInt(value)/100;
                        value = a.toString();
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String numberType = configgg.getString("numberType");
                    if(ObjectUtil.isNotEmpty(field) && "percentage".equals(numberType)){
                        if(field.equals(columnName)){
                            Double a = (double)Integer.parseInt(value)/100;
                            value = a.toString();
                        }
                    }
                }
            }
        }
        return value;
    }

    //自动编码
    public static String codingInForm(String columnName, String value, SysFormDO sysFormDO) {
        JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
        JSONArray fields = personData.getJSONArray("fields");
        if(ObjectUtil.isNotEmpty(fields)){
            for (int i = 0; i <fields.size() ; i++) {
                String field = fields.getJSONObject(i).getString("__vModel__");
                JSONObject config = fields.getJSONObject(i).getJSONObject("__config__");
                String tagIcon = config.getString("tagIcon");
                if(ObjectUtil.isNotEmpty(field) && "coding".equals(tagIcon)){
                    if(field.equals(columnName)){
                        String datatype = fields.getJSONObject(i).getString("dataType");
                    }
                }
            }
        }else{
            JSONObject config = personData.getJSONObject("__config__");
            JSONArray childrenRow = config.getJSONArray("children");
            for (int i = 0; i <childrenRow.size() ; i++) {
                JSONObject childrenOne = (JSONObject) childrenRow.get(i);
                JSONObject configg = childrenOne.getJSONObject("__config__");
                JSONArray childrenList = configg.getJSONArray("children");
                for (int j = 0; j <childrenList.size() ; j++) {
                    JSONObject children = (JSONObject) childrenList.get(j);
                    String field = children.getString("__vModel__");
                    JSONObject configgg = children.getJSONObject("__config__");
                    String tagIcon = configgg.getString("tagIcon");
                    if(ObjectUtil.isNotEmpty(field) && "coding".equals(tagIcon)){
                        if(field.equals(columnName)){
                            String datatype = children.getString("dataType");
                        }
                    }
                }
            }
        }
        return null;
    }
}

